package cn.mux.jdk8.arrays;

import java.util.Arrays;
import java.util.function.IntBinaryOperator;
import java.util.function.IntUnaryOperator;

/**
 * jdk8 arrays 新增方法
 * @author devin
 */
public class TestArrays {
	
		public static void main(String[] args) {
			int[] arr1 = {3,-4,25,16,30,18};
			//对数组并发排序
			Arrays.parallelSort(arr1);
			System.out.println(Arrays.toString(arr1));
			
			
			int[] arr2 = {3,-4,25,16,30,18};
			Arrays.parallelPrefix(arr2, new IntBinaryOperator() {
				
				
				/**
				 * left 带代表数组中前一个索引 处的元素,计算一个元素时，left为1
				 * right 代表数组中当前索引处的元素
				 */
				@Override
				public int applyAsInt(int left, int right) {
					return left*right;
				}
			});
			System.out.println(Arrays.toString(arr2));
			
			
			int[] arr3 = new int[5];
			Arrays.parallelSetAll(arr3,new IntUnaryOperator() {
				
				//operand 代表正在计算的元素索引
				@Override
				public int applyAsInt(int operand) {
					return operand*5;
				}
			});
			System.out.println(Arrays.toString(arr3));
		}

}
